#include "number.h"

/** Static member field. */
static const string NUMRULE_FLAG_MINUS    = "have_minus";

/** A not-so-surprising constructor.
 * The long parameter defaults to 0.
 * Note that only valid numbers can be created with this PUBLIC constructor.
 */
Number::Number(long l) : subtotal(0), value(l), first(true), valid(true) {
  flags.clear();
}

/** Return complete value.
 * For ease of handling, the sign is applied only here. 
 * The absolute value is the sum of subtotal + value.
 */
const long Number::getValue() {
  if (flags.find(NUMRULE_FLAG_MINUS)!=flags.end()) {
    return -(subtotal + value);
  } else {
    return subtotal + value;
  }
}

/** Getter function for first.
 * This toggle was set to false whenever something interesting had been parsed.
 */
const bool Number::isFirst() {
  return first;
}

/** The secret constructor.
 * This private constructor serves a sole purpose: create an invalid number.
 * of course, a valid one could be created as well, but that makes no sense.
 */
Number::Number(bool v) : subtotal(0.0), value(0.0), first(true), valid(v) {
  flags.clear();
}

/** The invalid number. */
const Number &Number::NOTANUMBER(false);

/** Standard operators. */
bool Number::operator==(Number other) {
  return (getValue() == other.getValue() && valid==other.valid);
}

/** Standard operators. */
bool Number::operator!=(Number other) {
  return (getValue() != other.getValue() || valid!=other.valid);
}
